package logic

import (
	"camera/B/Rpc/camera"
	"camera/B/Rpc/internal/svc"
	mysql2 "camera/B/Rpc/model/mysql"
	"context"
	"fmt"
	"gorm.io/gorm"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateStatusLogic {
	return &UserUpdateStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpdateStatusLogic) UserUpdateStatus(in *camera.UserUpdateStatusRequest) (*camera.UserUpdateStatusResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql2.User{
		Model:  gorm.Model{ID: uint(in.UserId)},
		Status: int(in.Status),
	}
	err := u.UpdateStatus(int(in.Status), int(in.UserId))
	if err != nil {
		return nil, fmt.Errorf("修改失败")
	}
	return &camera.UserUpdateStatusResponse{
		Success: true,
	}, nil
}
